use crate::service::calculator_client::CalculatorClient;
use crate::service::fs_protocol_lib_client::FsProtocolLibClient;
use crate::service::{Request,Result,LoginRequest,Response};

pub mod service {
    tonic::include_proto!("calculator");
    tonic::include_proto!("fs_protocol_lib");
}
#[tokio::main]
async fn main() {
    let request = Request { x:1,y:2 };
    let mut client = CalculatorClient::connect("http://localhost:8989")
        .await
        .expect("Assume the server is running.");
    match client.add(request).await {
        Ok(resp) => {
            let Result {
                result,
            } = resp.into_inner();
            println!("add result is {result}");
        }
        Err(status) => {
            println!("Client error: {status:?}");
        }
    }

    let request = Request { x:10,y:2 };
    match client.subtract(request).await {
        Ok(resp) => {
            let Result { result} = resp.into_inner();
            println!("subtract result is {result}");
        }
        Err(status) => {
            println!("Client error: {status:?}");
        }
    }

    let mut client = FsProtocolLibClient::connect("http://localhost:8989")
        .await
        .expect("Assume the server is running.");
    let request = LoginRequest { username:"zing".to_owned(),password:"123456".to_owned() };
    match client.login(request).await {
        Ok(resp) => {
            let Response { msg,code,..} = resp.into_inner();
            println!("login result is {msg}  {code}");
        }
        Err(status) => {
            println!("Client error: {status:?}");
        }
    }
}
